package com.lagou.task.servlet;

import com.lagou.task.model.Student;
import com.lagou.task.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AddServlet", urlPatterns = "/add")
public class AddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        StudentService studentService = new StudentService();
        String sName = request.getParameter("sName");
        String sSex = request.getParameter("sSex");
        String sBirth = request.getParameter("sBirth");
        String sEmail = request.getParameter("sEmail");
        String sNote = request.getParameter("sNote");
        int i = studentService.studentAddService(new Student(sName, sSex, sBirth, sEmail, sNote));
        if(i!=0){
            System.out.println("添加成功！");
        }
        response.sendRedirect("main.jsp");
    }
}
